1 Imports System.Data.SqlClient
2 Public Class frmInactive
3 Dim Status As String
4 Sub fillSession()
5 Try
6 con = New SqlConnection(cs)
7 con.Open()
8 adp = New SqlDataAdapter()
9 adp.SelectCommand = New SqlCommand("SELECT distinct (Session) FROM Student", con)
10 ds = New DataSet("ds")
11 adp.Fill(ds)
12 dtable = ds.Tables(0)
13 cmbSession.Items.Clear()
14 For Each drow As DataRow In dtable.Rows
15 cmbSession.Items.Add(drow(0).ToString())
16 Next
17 Catch ex As Exception
18 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
19 End Try
20 End Sub
21
22 Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
23 Me.Close()
24 End Sub
25 Sub Reset()
26 cmbClass.SelectedIndex = -1
27 cmbSection.SelectedIndex = -1
28 cmbSession.SelectedIndex = -1
29 listView1.Items.Clear()
30 cmbClass.Enabled = False
31 cmbSection.Enabled = False
32 btnUpdate.Enabled = False
33 End Sub
34 Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
35 Reset()
36 End Sub
37
38 Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
39 Try
40 If listView1.Items.Count = 0 Then
41 MessageBox.Show("Sorry nothing to update.." & vbCrLf & "Please retrieve data in listview", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
42 Exit Sub
43 End If
44 For i As Integer = listView1.Items.Count - 1 To 0 Step -1
45 con = New SqlConnection(cs)
46 If listView1.Items(i).Checked = True Then
47 Status = "Inactive"
48 Else
49 Status = "Active"
50 End If
51 Dim cd As String = "update Student set Status= '" & Status & "' where AdmissionNo=@d1"
52 cmd = New SqlCommand(cd)
53 cmd.Parameters.AddWithValue("@d1", listView1.Items(i).SubItems(0).Text)
54 cmd.Connection = con
55 con.Open()
56 cmd.ExecuteNonQuery()
57 con.Close()
58 Next
59 MessageBox.Show("Successfully updated", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
60 btnUpdate.Enabled = False
61 Catch ex As Exception
62 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
63 End Try
64 End Sub
65
66
67 Private Sub cmbSession_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbSession.SelectedIndexChanged
68 Try
69 cmbClass.Enabled = True
70 con = New SqlConnection(cs)
71 con.Open()
72 Dim ct As String = "SELECT distinct RTRIM(ClassName) FROM Student,Section,Class where Student.SectionID=Section.ID and Section.Class=Class.ClassName and Session=@d1"
73 cmd = New SqlCommand(ct)
74 cmd.Connection = con
75 cmd.Parameters.AddWithValue("@d1", cmbSession.Text)
76 rdr = cmd.ExecuteReader()
77 cmbClass.Items.Clear()
78 While rdr.Read
79 cmbClass.Items.Add(rdr(0))
80 End While
81 con.Close()
82 Catch ex As Exception
83 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
84 End Try
85 End Sub
86
87 Private Sub cmbClass_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbClass.SelectedIndexChanged
88 Try
89 cmbSection.Enabled = True
90 con = New SqlConnection(cs)
91 con.Open()
92 Dim ct As String = "SELECT distinct RTRIM(SectionName) FROM Student,Section,Class where Student.SectionID=Section.ID and Section.Class=Class.ClassName and Session=@d1 and ClassName=@d2"
93 cmd = New SqlCommand(ct)
94 cmd.Connection = con
95 cmd.Parameters.AddWithValue("@d1", cmbSession.Text)
96 cmd.Parameters.AddWithValue("@d2", cmbClass.Text)
97 rdr = cmd.ExecuteReader()
98 cmbSection.Items.Clear()
99 While rdr.Read
100 cmbSection.Items.Add(rdr(0))
101 End While
102 con.Close()
103 Catch ex As Exception
104 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
105 End Try
106 End Sub
107
108 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs)
109 Try
110 If Len(Trim(cmbSession.Text)) = 0 Then
111 MessageBox.Show("Please select session", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
112 cmbSession.Focus()
113 Exit Sub
114 End If
115 If Len(Trim(cmbClass.Text)) = 0 Then
116 MessageBox.Show("Please select class", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
117 cmbClass.Focus()
118 Exit Sub
119 End If
120 If Len(Trim(cmbSection.Text)) = 0 Then
121 MessageBox.Show("Please select section", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
122 cmbSection.Focus()
123 Exit Sub
124 End If
125 con = New SqlConnection(cs)
126 con.Open()
127 cmd = New SqlCommand("select AdmissionNo,StudentName From from Student,ClassInfo,Section,SchoolInfo where Student.SectionID=Section.ID and ClassInfo.ClassName=Section.Class and SchoolInfo.S_ID=Student.SchoolID and Session=@d1 and ClassName=@d2 and SectionName=@d3 order by StudentName", con)
128 cmd.Parameters.AddWithValue("@d1", cmbSession.Text)
129 cmd.Parameters.AddWithValue("@d2", cmbClass.Text)
130 cmd.Parameters.AddWithValue("@d3", cmbSection.Text)
131 rdr = cmd.ExecuteReader()
132 While rdr.Read()
133 Dim item = New ListViewItem()
134 item.Text = rdr(0).ToString().Trim()
135 item.SubItems.Add(rdr(1).ToString().Trim())
136 listView1.Items.Add(item)
137 End While
138 Catch ex As Exception
139 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
140 End Try
141 End Sub
142
143 Private Sub btnGetData_Click(sender As System.Object, e As System.EventArgs) Handles btnSearch.Click
144 Try
145 btnUpdate.Enabled = True
146 If Len(Trim(cmbSession.Text)) = 0 Then
147 MessageBox.Show("Please select session", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
148 cmbSession.Focus()
149 Exit Sub
150 End If
151 If Len(Trim(cmbClass.Text)) = 0 Then
152 MessageBox.Show("Please select class", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
153 cmbClass.Focus()
154 Exit Sub
155 End If
156 If Len(Trim(cmbSection.Text)) = 0 Then
157 MessageBox.Show("Please select section", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
158 cmbSection.Focus()
159 Exit Sub
160 End If
161 con = New SqlConnection(cs)
162 con.Open()
163 cmd = New SqlCommand("select Student.AdmissionNo,StudentName,Student.Status from Student,Class,Section,SchoolInfo where Student.SectionID=Section.ID and Class.ClassName=Section.Class and SchoolInfo.S_ID=Student.SchoolID and Session=@d1 and ClassName=@d2 and SectionName=@d3 and Student.Status='Active' order by StudentName", con)
164 cmd.Parameters.AddWithValue("@d1", cmbSession.Text)
165 cmd.Parameters.AddWithValue("@d2", cmbClass.Text)
166 cmd.Parameters.AddWithValue("@d3", cmbSection.Text)
167 rdr = cmd.ExecuteReader()
168 While rdr.Read()
169 Dim item = New ListViewItem()
170 item.Text = rdr(0).ToString().Trim()
171 item.SubItems.Add(rdr(1).ToString().Trim())
172 item.SubItems.Add(rdr(2).ToString().Trim())
173 listView1.Items.Add(item)
174 For i As Integer = listView1.Items.Count - 1 To 0 Step -1
175 If listView1.Items(i).SubItems(2).Text = "Yes" Then
176 listView1.Items(i).Checked = True
177 Else
178 listView1.Items(i).Checked = False
179 End If
180 Next
181 End While
182 Catch ex As Exception
183 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
184 End Try
185 End Sub
186
187 Private Sub frmDiscount_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
188 fillSession()
189 End Sub
190
191 Private Sub BtnClose1_Click(sender As System.Object, e As System.EventArgs)
192 Me.Close()
193 End Sub
194
195 End Class